<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    .box {
      width: 200px;
      height: 200px;
      background-color: red;
    }
    .father {
      width: 200px;
      height: 200px;
      background-color: lightblue;
    }
    .son {
      width: 100px;
      height: 100px;
      background-color: lightcoral;
    }
  </style>
</head>
<body>
  <div id="app">
    <h1>事件处理2</h1>
    <h3>事件对象event</h3>
    <div class="box" @click="fn(2)"></div>
    <br>
    <!-- <div class="box" @click="fn(3, $event)"></div> -->

    <h3>事件修饰符</h3>
    <!-- .stop修饰符表示阻止冒泡 -->
    <!-- .prevent修饰符表示阻止默认行为 -->
    <div class="father" @click="fatherClick">
      <div class="son" v-on:click.stop="sonClick"></div>
    </div>
    <a href="" @click.prevent="aClick">哈哈</a>

    <br>

    <h3>按键修饰符</h3>
    <input type="text" @input="inputChange" @keydown.enter="keydown">
  </div>

  <script src="../Vue.js"></script>

  <script>
    const { createApp } = Vue;

    createApp({
      data() {
        return {}
      },
      methods: {
        fn(n, e) {
          // 在事件处理函数中，可以直接获得event事件对象(上面v-on指令里面没有加小括号)
          // 当v-on指令上面已经添加小括号的情况下，需要手动传入$event
          console.log(n);
          console.log(e);
        },
        fatherClick() {
          console.log("fatherClick");
        },
        // sonClick(event) {
        //   event.stopPropagation()
        //   console.log("sonClick");
        // }
        sonClick() {
          console.log("sonClick");
        },
        aClick() {
          console.log("aClick");
        },
        inputChange(e) {
          console.log(e.target.value);
        },
        keydown(e) {
          console.log(e.keyCode);
          if (e.key === "Enter") {}
        }
      }
    }).mount("#app")

  </script>
</body>
</html>